package com.yvon.maple.service.msg.core.common.enums;


import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

/**
 * 发送ID类型枚举
 *
 * @author : Yvon
 * @since : 2021-12-22
 */
@Getter
@ToString
@AllArgsConstructor
public enum IdType {
    USER_ID(10, "userId", "用户ID"),
    DID(20, "did", ""),
    PHONE(30, "phone", "手机号"),
    OPEN_ID(40, "openId", "微信OpenID"),
    EMAIL(50, "email", "电子邮件");


    private final Integer code;

    /**
     * 英文标识
     */
    @EnumValue
    private final String codeEn;


    private final String description;


    @JsonValue
    public String getCodeEn() {
        return codeEn;
    }

    /**
     * 通过code获取enum
     * @param code
     * @return
     */
    public static IdType getEnumByCode(Integer code) {
        IdType[] values = values();
        for (IdType value : values) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

    /**
     * 通过codeEn获取enum
     * @param codeEn
     * @return
     */
    public static IdType getEnumByCodeEn(String codeEn) {
        IdType[] values = values();
        for (IdType value : values) {
            if (value.getCodeEn().equals(codeEn)) {
                return value;
            }
        }
        return null;
    }

}
